<template>
  <div class="box4" ref="map"></div>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue'
import * as echarts from 'echarts'
//引入中国地图的JSON数据
import chinaJSON from './china.json'
//引入地图背景
import myimg from '../../../../assets/images/guoqi.png'

//获取DOM元素
let map = ref()
//注册中国地图
echarts.registerMap('china', chinaJSON as any)
onMounted(() => {
  let mycharts = echarts.init(map.value)
  //设置配置项
  mycharts.setOption({
    //地图组件
    geo: {
      map: 'china',
      roam: true, //鼠标滚轮缩放
      width: '800px',
      top: 70,
      left: 70,
      //地图上的文字的设置
      label: {
        show: true, //文字显示出来
        color: 'white',
        fontSize: 14,
      },
      //每一个多边形的样式
      itemStyle: {
        areaColor: {
          image: myimg,
          repeat: 'repeat',
        },
      },
      //地图高亮效果
      emphasis: {
        itemStyle: {
          color: 'green',
        },
        label: {
          color: 'white',
          fontSize: 30,
        },
      },
      z: 2,
    },
    series: [
      {
        type: 'lines', //航线的系列
        data: [
          {
            coords: [
              [116.405285, 39.904989], //起点
              [113.280637, 23.125178], //终点
            ],
            //统一的样式配置
            lineStyle: {
              color: 'skyblue',
              width: 3,
              curveness: 0.2,
            },
          },
          {
            coords: [
              [113.280637, 23.125178], //起点
              [116.405285, 39.904989], //终点
            ],
            //统一的样式配置
            lineStyle: {
              color: 'skyblue',
              width: 3,
              curveness: 0.2,
            },
          },
          {
            coords: [
              [113.280637, 23.125178], //起点
              [121.472644, 31.231706], //终点
            ],
            //统一的样式配置
            lineStyle: {
              color: 'skyblue',
              width: 3,
              curveness: 0.2,
            },
          },
          {
            coords: [
              [121.472644, 31.231706], //终点
              [113.280637, 23.125178], //起点
            ],
            //统一的样式配置
            lineStyle: {
              color: 'skyblue',
              width: 3,
              curveness: 0.2,
            },
          },
          {
            coords: [
              [113.280637, 23.125178], //起点
              [104.065735, 30.659462], //终点
            ],
            //统一的样式配置
            lineStyle: {
              color: 'skyblue',
              width: 3,
              curveness: 0.2,
            },
          },
          {
            coords: [
              [104.065735, 30.659462], //终点
              [113.280637, 23.125178], //起点
            ],
            //统一的样式配置
            lineStyle: {
              color: 'skyblue',
              width: 3,
              curveness: 0.2,
            },
          },
          {
            coords: [
              [116.405285, 39.904989], //起点
              [101.778916, 36.623178], //终点
            ],
            //统一的样式配置
            lineStyle: {
              color: 'skyblue',
              width: 3,
              curveness: 0.2,
            },
          },
          {
            coords: [
              [101.778916, 36.623178], //终点
              [116.405285, 39.904989], //起点
            ],
            //统一的样式配置
            lineStyle: {
              color: 'skyblue',
              width: 3,
              curveness: 0.2,
            },
          },
        ],
        //开启动画特效
        effect: {
          show: true,
          symbol: 'arrow',
          color: 'blue',
          symbolSize: 10,
        },
      },
      {
        type: 'effectScatter',
        coordinateSystem: 'geo',
        rippleEffect: {
          number: 2,
          scale: 3,
          brushType: 'stroke',
        },
        itemStyle: {
          // color: '#F56828',
          color: 'green',
        },
        // label: {
        //   show: true,
        //   offset: [40, 0],
        //   color: '#F56828',
        // },
        data: [
          {
            value: [116.405285, 39.904989],
          },
          {
            value: [113.280637, 23.125178],
          },
          {
            value: [121.472644, 31.231706],
          },
          {
            value: [104.065735, 30.659462],
          },
          {
            value: [101.778916, 36.623178],
          },
        ],
      },
    ],
  })
})
</script>

<style scoped></style>
